/**

 * @author admin

 * 2014年8月3日

 */

package com.tmall.testgen.plugin.wizards.runinspring.listener;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;

import com.tmall.testgen.client.ClientDataCenter;
import com.tmall.testgen.common.bo.interact.back.InterceptInfo;
import com.tmall.testgen.plugin.views.vo.SpringTree;

public class DeleteTestTreeListener implements SelectionListener{
	private TreeViewer treeViewer;
	

	public DeleteTestTreeListener(TreeViewer treeViewer){
		this.treeViewer=treeViewer;
	}

	@Override
	public void widgetSelected(SelectionEvent arg0) {
		IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
		SpringTree currentTree = (SpringTree) selection.getFirstElement();
		if (currentTree == null) {
			return;
		}
		if(currentTree.getValue()==null||!(currentTree.getValue() instanceof InterceptInfo)){
			return;
		}
		
		ClientDataCenter.getInstance().removeUserInfo((InterceptInfo) currentTree.getValue());
		currentTree.getParent().removeChild(currentTree);
		
		treeViewer.refresh();		
	}
	
	@Override
	public void widgetDefaultSelected(SelectionEvent arg0) {
	}

}
